<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>


<script language="JavaScript">
    function checkExistBookmark(itemId) {
        document.getElementById("indicator").style.display = "";
        
        try {
            var xmlHttp;
            try {     // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
            } catch (e)   { // Internet Explorer
            try {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)  {
                try  {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e)  {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState==4) {
            text = xmlHttp.responseText;   
            // alert(text);
            try { //Internet Explorer 
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async="false";
                xmlDoc.loadXML(text);
            } catch(e) {
            try { // Firefox, Mozilla, Opera, etc.
                parser=new DOMParser();
                xmlDoc=parser.parseFromString(text,"text/xml");
            } catch(e) {
            alert(e.message);
            return;
        }
    }
    
    var result = xmlDoc.getElementsByTagName("result")[0].childNodes[0].nodeValue;
    if (result == "false") {
        //document.getElementById('linkBookmark').click();
        document.getElementById('isSkipFlag').value='true';
        // set bookmarkflag

        document.getElementById('form2').submit();
    }
    else if (result == "true") {
        alert("เคย bookmark แล้ว");
    } else if (result=='N'){
        alert('พบข้อผิดพลาด กรุณาทดลองใหม่อีกครั้ง');
    }
    document.getElementById("indicator").style.display = "none";
}
}

var date1 = new Date();
var recordId = date1.getTime();
var url = '/bookmark/CheckExistBookmarkServlet?itemId='+itemId+'&recordId='+recordId;

xmlHttp.open("GET", url, true);
xmlHttp.send(null);

return true;
}
catch (e) {
    document.getElementById("indicator").style.display = "none";
}
}
</script>


<span style="display:none">
    <a id="linkBookmark" href="/bookmark/AddBookmarkAction.do?_flowId=flow2&url=/LMSProject/showItem.do?id=${requestScope.ITEM_VIEW_ATTR.itemId}" class="WH12" style="cursor:pointer">Set bookmark</a>
</span>

<!--a onclick="checkExistBookmark('${requestScope.ITEM_VIEW_ATTR.itemId}')" class="WH12" style="cursor:pointer">Set bookmark</a-->

<span id="indicator" style="display:none">
    <html:img page="/images/indicator.gif" />
</span>

<form method=post action="/bookmark/AddBookmarkAction.do" name="form2" id="form2" onsubmit="document.getElementById('isSkipFlag').value='true';">
    <input type="hidden" name="_flowId" value="flow2" />
    <input type="hidden" name="url" value="/LMSProject/showItem.do?id=${requestScope.ITEM_VIEW_ATTR.itemId}" />
    <input type="hidden" name="itemId" value="${requestScope.ITEM_VIEW_ATTR.itemId}" />
    <input type="hidden" name="redirect" value="/LMSProject/eitem.do?id=${requestScope.ITEM_VIEW_ATTR.itemId}&path=${requestScope.ITEM_VIEW_ATTR.itemCode}&refId=${param.refId}" />
    <input type="submit" value="bookmark"/>
</form>
